const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');

const app = express();
// const bodyParser = require('body-parser');
//
// app.use( bodyParser.json() );       // to support JSON-encoded bodies
// app.use( bodyParser.urlencoded({ extended: true }) ); // to support URL-encoded bodies

app.all("*",function(req,res,next){
  res.header("Access-Control-Allow-Origin","*");
  res.header("Access-Control-Allow-Headers","content-type,s-token");
  res.header("Access-Control-Allow-Credentials","true");
  res.header("Access-Control-Allow-Methods","DELETE,PUT,POST,GET,OPTIONS");
  if (req.method.toLowerCase() === 'options')
    res.sendStatus(200);
  else
    next();
});

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

require('./routes/manager')(app);
require('./routes/web')(app);
require('./routes/work')(app);
require('./routes/wechat')(app);
// app.use('/student', studentRouter);
// app.use('/users', usersRouter);
// app.use('/work', workRouter);
// app.use('/api', webRouter);

module.exports = app;
